home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / proc / machTypeSparc.c < prev    next >
C/C++ Source or Header  |  1991-03-16  |  3KB  |  101 lines

  1. /* 
  2.  * machTypeSparc.c --
  3.  *
  4.  *    Contains the machine specific routine for determining if
  5.  *      a file is an object file for a Sun 4.
  6.  *
  7.  * Copyright 1989 Regents of the University of California
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  */
  16.  
  17. #ifndef lint
  18. static char rcsid[] = "$Header: /sprite/src/attcmds/file/RCS/machTypeSparc.c,v 1.3 90/10/19 15:25:45 jhh Exp Locker: shirriff $";
  19. #endif /* not lint */
  20.  
  21. #include <sun4.md/sys/exec.h>
  22. #include <sun4.md/a.out.h>
  23. #include "file.h"
  24.  
  25.  
  26. /*
  27.  *----------------------------------------------------------------------
  28.  *
  29.  * machTypeSparc --
  30.  *
  31.  *    Determine if the file is a sparc-specific file type.
  32.  *
  33.  * Results:
  34.  *    If successful, return the name of the machine.  Otherwise
  35.  *      return NULL.
  36.  *
  37.  * Side effects:
  38.  *    Modifies the `magic' number.
  39.  *
  40.  *----------------------------------------------------------------------
  41.  */
  42.  
  43. char *
  44. machTypeSparc(bufferSize, buffer, magic, syms, other)
  45.     int        bufferSize;    /* size of buffer */
  46.     char    *buffer;    /* buffer containing header */
  47.     int         *magic;         /* pointer to magic number */
  48.     int         *syms;          /* pointer to symbols */
  49.     char    **other;    /* other information to return */
  50. {
  51.  
  52.     struct exec        *header;
  53.     char        swappedHeader[sizeof(*header) * 2];
  54.     int            swappedSize = sizeof(swappedHeader);
  55.     int            status;
  56.  
  57.     *other = "";
  58.  
  59.     if (bufferSize < sizeof(struct exec)) {
  60.     return NULL;
  61.     }
  62.     header = (struct exec *) buffer;
  63.     if (!N_BADMAG(*header)) {
  64.     *magic = header->a_magic;
  65.     *syms = header->a_syms;
  66.     if (header->a_machtype == M_SPARC) {
  67.         /*
  68.          * We can't just use the declared bitfield to check for
  69.          * dynamic, since the bitorder is different on different
  70.          * machines.
  71.          */
  72.         if (((unsigned char *)header)[0]&0x80) {
  73.         *other = "dynamically linked";
  74.         }
  75.         return "sparc";
  76.     }
  77.     }
  78.     if (FMT_SPARC_FORMAT != hostFmt) {
  79.     status = Fmt_Convert("{b1b1h1w7}", FMT_SPARC_FORMAT, &bufferSize,
  80.         (char *) buffer, hostFmt, &swappedSize, swappedHeader);
  81.     if (status) {
  82. #ifndef KERNEL
  83.         fprintf(stderr, "Fmt_Convert returned %d.\n", status);
  84. #endif
  85.         return NULL;
  86.     }
  87.     header = (struct exec *) swappedHeader;
  88.     if (!N_BADMAG(*header)) {
  89.         *magic = header->a_magic;
  90.         *syms = header->a_syms;
  91.         if (header->a_machtype == M_SPARC) {
  92.         if (((unsigned char *)header)[0]&0x80) {
  93.             *other = "dynamically linked";
  94.         }
  95.         return "sparc";
  96.         }
  97.     }
  98.     }
  99.     return NULL;
  100. }
  101.